package oj;

import java.util.Scanner;

public class Day16S {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()){
            String card="345678910JQKA2jokerJOKER";
            String s=sc.nextLine();
            if(s.contains("joker JOKER")){
                System.out.println("joker JOKER");
            }else {
                String[] str=s.split("-");
                String[] left=str[0].split(" ");
                String[] right=str[1].split(" ");
                if(left.length == 4 && right.length != 4){
                   System.out.println(str[0]);
                }else if(right.length == 4 && left.length!=4){
                    System.out.println(str[1]);
                }else if(left.length == right.length){
                    String card2 = card.indexOf(left[0]) > card.indexOf(right[0]) ? str[0] : str[1];
                    System.out.println(card2);
                }else {
                    System.out.println("ERROR");
                }
            }
        }
    }
}
